USE [web-vote]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_voto_candidato]') AND parent_object_id = OBJECT_ID(N'[dbo].[voto]'))
ALTER TABLE [dbo].[voto] DROP CONSTRAINT [FK_voto_candidato]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_voto_tipo_voto]') AND parent_object_id = OBJECT_ID(N'[dbo].[voto]'))
ALTER TABLE [dbo].[voto] DROP CONSTRAINT [FK_voto_tipo_voto]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_voto_usuario]') AND parent_object_id = OBJECT_ID(N'[dbo].[voto]'))
ALTER TABLE [dbo].[voto] DROP CONSTRAINT [FK_voto_usuario]
GO

USE [web-vote]
GO

/****** Object:  Table [dbo].[voto]    Script Date: 10/05/2013 10:43:14 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[voto]') AND type in (N'U'))
DROP TABLE [dbo].[voto]
GO

USE [web-vote]
GO

/****** Object:  Table [dbo].[voto]    Script Date: 10/05/2013 10:43:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[voto](
	[id_voto] [int] IDENTITY(1,1) NOT NULL,
	[id_usuario] [int] NOT NULL,
	[id_candidato] [int] NOT NULL,
	[fecha] [datetime] NOT NULL,
	[id_tipo_voto] [int] NOT NULL,
	[id_eleccion] [int] NULL,
 CONSTRAINT [PK_voto] PRIMARY KEY CLUSTERED 
(
	[id_voto] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[voto]  WITH CHECK ADD  CONSTRAINT [FK_voto_candidato] FOREIGN KEY([id_candidato])
REFERENCES [dbo].[candidato] ([id_candidato])
GO

ALTER TABLE [dbo].[voto] CHECK CONSTRAINT [FK_voto_candidato]
GO

ALTER TABLE [dbo].[voto]  WITH CHECK ADD  CONSTRAINT [FK_voto_tipo_voto] FOREIGN KEY([id_tipo_voto])
REFERENCES [dbo].[tipo_voto] ([id_tipo_voto])
GO

ALTER TABLE [dbo].[voto] CHECK CONSTRAINT [FK_voto_tipo_voto]
GO

ALTER TABLE [dbo].[voto]  WITH CHECK ADD  CONSTRAINT [FK_voto_usuario] FOREIGN KEY([id_usuario])
REFERENCES [dbo].[usuario] ([id_Usuario])
GO

ALTER TABLE [dbo].[voto] CHECK CONSTRAINT [FK_voto_usuario]
GO


